#pragma once

#include "ftp/IChannel.h"
#include "ftp/FileSystem.h"

namespace ftp
{

enum DataType
{
	kImageDataType,
	kAsciiDataType,
	kEbicdicDataType,
	kLocalDataType
};

class ServerPI : public IChannelSync
{
public:
	ServerPI(std::auto_ptr<IChannel> channel, FileSystem* fileSystem);
	virtual ~ServerPI();

	virtual void onBytesRead(bool ok, const char* bytes, size_t bytesSize);
	virtual void onBytesWrote(bool ok);

private:
	void handleUserCommand(const std::string& arg);
	void handlePwdCommand(const std::string& arg);
	void handleListCommand(const std::string& arg);
	void handlePortCommand(const std::string& arg);
	void handlePasvCommand(const std::string& arg);
	void handleTypeCommand(const std::string& arg);

private:
	std::auto_ptr<IChannel> m_channel;
	FileSystem* m_fileSystem;
	
	std::string m_workingDir;
	DataType m_dataType;

	bool m_disconnected;
};

} //ftp

